package com.hand.dao;

import com.hand.entity.Country;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.List;


/*******************Copyright Information************************
 *              AUTHOR: Lorin.Mitchell                           *
 *              DATE: 2017/11/6                                 *
 *              TIME: 19:05                                      * 
 ****************************************************************/

@Component
public class CountryRepository {

    @Autowired
    private InfCountryRepository repository;

    public Country findCountry(String name){
        Assert.notNull(name, "The country's name must not be null");
        Country country = this.repository.findOne(name);
        return country;
    }

    public List<Country> findCountries() {
        List<Country> list = this.repository.findAll();
        return list;
    }

    public void save(Country country){
        repository.save(country);
    }

    public void deleteByCap(String cap){
        repository.delete(repository.findCountriesByCapital(cap));
    }
}
